package uvt.gui.mainframe.subpanel.addvehicle;

import java.awt.Color;

import javax.swing.JComboBox;
import javax.swing.JLabel;

import uvt.gui.mainframe.object.memento.ButtonOperations;
import uvt.gui.mainframe.object.memento.MementoImp;
import uvt.gui.mainframe.object.memento.UndoOperationButton;
import uvt.gui.mainframe.object.observer.ConcreteObservable;
import uvt.gui.mainframe.subpanel.PanelAddParent;
import uvt.gui.mainframe.subpanel.addroute.RouteNameTextField;

public class PanelAddVehicle extends PanelAddParent {
	
	private VehicleNameTextField txtVehicleName;
	private RouteNameTextField txtRouteName;
	private JComboBox<String> vehicleType;
	private AddVehicleButton btnAddVehicle;
	private UndoOperationButton btnUndoVehicle;
	private MementoImp memento;
	
	public PanelAddVehicle() {
		setBackground(Color.white);
		
		JLabel lblName = new JLabel("Name:");
		add(lblName);
		txtVehicleName = new VehicleNameTextField();
		add(txtVehicleName);
		
		String list[] = {"Tram","Trolleybus","Bus"};
		
		vehicleType = new JComboBox<String>(list);
		vehicleType.setSelectedIndex(0);
		add(vehicleType);
		
		JLabel lblRoute = new JLabel("Route:");
		add(lblRoute);
		
		txtRouteName = new RouteNameTextField();
		add(txtRouteName);
		
		memento = new MementoImp();
		
		btnUndoVehicle = new UndoOperationButton(ButtonOperations.ADDVEHICLE);
		btnUndoVehicle.addActionListener(this);
		
		btnAddVehicle = new AddVehicleButton(txtVehicleName,txtRouteName,vehicleType,
				                             btnUndoVehicle,memento);
		btnAddVehicle.addActionListener(this);
		add(btnAddVehicle);
		
		add(btnUndoVehicle);	
		
		ConcreteObservable.getVehiclePanelObservableInstance().attach(txtVehicleName);
		ConcreteObservable.getRoutePanelObservableInstance().attach(txtRouteName);
	}
	
	public void cleanPanel() {
		txtVehicleName.setText("");
		map.removeAllMapMarkers();
		map.removeAllMapPolygons();
	}

}